<?php
/**
 * 手机应用WML格式输出
 * 
 * $Id: wml.functions.php 122 2010-05-28 10:05:16Z Administrator $
 * $Revision: 122 $
 * $Author: Administrator $
 * $Date: 2010-05-28 18:05:16 +0800 (星期五, 28 五月 2010) $
 * 本组件无需服务器支持，实现手机应用wml1.0,wml 1.1 wml 1.2
 * 可以输出多个卡片,每个卡片都有相应的属性如(标题，ID)
 * 输出卡片组头部信息
 * 
 * Wml2.0不使用本类生成,本类可以 wml1.0,1.1,1.2。
 * 
 * 
 * @author glzaboy<glzaboy@163.com>
 * @package fastlib
 * @subpackage functions
 * @copyright 2005-2010 (c) glzaboy
 */
if (! defined ( '__FASTLIB__' )) {
	if (__DEBUG__) {
		die ( sprintf ( 'Forbidden 403 at file %s on line %d', __FILE__, __LINE__ ) );
	} else {
		die ( 'Forbidden 403' );
	}
}
/**
 * 判断是否已经载入过fasttpl
 */
if (! class_exists ( "fasttpl" )) {
	loadClass ( 'fasttpl', __FILE__, __LINE__ );
}
/**
 * 初始化卡片组
 *
 * @return Array 空的卡片组
 */
function wmlGroups() {
	return array ("head" => array ('access' => array (), 'meta' => array () ), "card" => array () );
}
/**
 * 初始化一个卡片
 *
 * @param string $delimiter 模板分隔号
 * @param String $skin SKIN
 * @param Sting $dir 目录当为relate时是相对于SKIN找模板
 * @return object Smarty对象
 */
function wmlCard($delimiter = '', $skin = null) {
	return new fasttpl ( null, $delimiter, $skin );
}
/**
 * 设置卡片中的Smarty变量
 *
 * @param object $card wmlCard得到的对象
 * @param String $name 变量名称
 * @param mixed $value PHP变量
 */
function wmlSetvar(&$card, $name, $value) {
	$card->assign ( $name, $value );
}
/**
 * 增加一个卡片到到卡片组
 *
 * @param Array $wmlGroup 由wmlGroups得到的句柄
 * @param object $card 卡片
 * @param String $tpl 对本卡片使用的模板
 * @param Array $cardinf 卡片信息
 */
function wmlAddcard(&$wmlGroup, &$card, $tpl, $cardinf) {
	$tmp = array ();
	$tmp ['wml'] = $card->fetch ( $tpl );
	$tmp ['card'] = $cardinf;
	array_push ( $wmlGroup ['card'], $tmp );
	$card = null;
}
/**
 * 卡片组头部设置
 *
 * @param Array $wmlGroup 由wmlGroups得到的句柄
 * @param mixed $headinf 头信息
 * @param Sting $type 头部类型 为access时输出access，其它的为meta
 */
function wmlSethead(&$wmlGroup, $headinf, $type = "access") {
	if ($type === "access") {
		array_push ( $wmlGroup ['head'] ['access'], $headinf );
	} else {
		array_push ( $wmlGroup ['head'] ['meta'], $headinf );
	}
}
/**
 * 输出卡片组
 *
 * @param Array $wmlGroup 由wmlGroups得到的句柄
 * @param bool $expires 缓存控制时间为秒
 */
function wmlOutput($wmlGroup, $charset = null, $expires = null) {
	global $sitecfg;
	ob_clean ();
	setHeader ( "wml", $charset ? $charset : $sitecfg ['charset'] );
	wmlSethead ( $wmlGroup, array ('http-equiv' => 'Content-Type', 'content' => 'text/vnd.wap.wml;charset=' . ($charset ? $charset : $sitecfg ['charset']) ), 'meta' );
	setHeader ( 'cache', $expires );
	$wmltpl = new fasttpl ( '' );
	$wmltpl->assign ( "wml", $wmlGroup );
	$wmltpl->display ( __FASTTPL__ . "wml.fs" );
}
/**
 * 返回本模块信息
 *
 * @return string
 */
function wmlprintInfo() {
	$version = '$Revision: 122 $';
	$moudle = explode ( "functions", __FILE__ );
	$moudle = $moudle [1] ? substr ( $moudle [1], 1 ) . 'functions' : $moudle;
	$return = '';
	$return .= startTable ();
	$return .= printRow ( array (array ('class' => 'h', 'content' => '<center>' . $moudle . '</center>', 'colspan' => '2' ) ) );
	$return .= printRow ( array (array ('class' => 'e', 'content' => 'author' ), array ('class' => 'v', 'content' => 'glzaboy' ) ) );
	$return .= printRow ( array (array ('class' => 'e', 'content' => 'version' ), array ('class' => 'v', 'content' => $version ) ) );
	$return .= printRow ( array (array ('class' => 'e', 'content' => 'Support' ), array ('class' => 'v', 'content' => 'wml 1.1,wml1.2' ) ) );
	$return .= printRow ( array (array ('class' => 'e', 'content' => 'Dependence' ), array ('class' => 'v', 'content' => 'smarty,fasttpl' ) ) );
	$return .= endTable ();
	return $return;
}